import Vue from 'vue'
import ElementUI from 'element-ui'
import VueRouter from 'vue-router'
import 'element-ui/lib/theme-chalk/index.css'
import routers from './routers'
import App from './App.vue'
import VueWechatTitle from 'vue-wechat-title'
import axios from 'axios'
import store from './store'




Vue.use(ElementUI)
Vue.use(VueRouter)
Vue.use(VueWechatTitle)
Vue.prototype.$axios= axios
Vue.config.productionTip = false

const router = new VueRouter({
  mode: 'history',
  base: __dirname,
  routes: routers
})

const routerPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(error=> error)
}

router.beforeEach((to, from, next) => {
  // 此处判断条件我有看到其他人用to.matched.length ===0进行判断， 具体的还有待进一步验证，大体的思路就是这样的
  if (to.fullPath === '/' || to.fullPath === '/index') {
    from.name ? next({ name:from.name }) : next('/index/home');
  } else {
    next(); //如果匹配到正确跳转
  }
})

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
